1. Field of the Invention
Methods and apparatuses consistent with the present invention relate to writing a file, and more particularly, to a method for writing a file by different writing schemes according to file characteristics, and an electronic device using the method.
2. Description of the Related Art
A NAND flash memory is a type of related art semiconductor memory element for writing files. The NAND flash memory consumes less power and is more compact than a hard disk drive (HDD), and has thus become widely used.
Unlike an HDD, the NAND flash memory cannot be overwritten. Accordingly, two steps of erasing and writing must be performed. Further, reading and writing is performed by the page, whereas deleting is performed by the block, i.e., a write area consisting of a plurality of pages.
Furthermore, the related art NAND flash memory, unlike an HDD, has no separate write area for metadata for a file.
As a result of such differences, the related art method for writing a file to a NAND flash memory is also different from that of writing a file to an HDD. The method for writing a file to a NAND flash memory is described in detail below with reference to FIG. 1.
FIG. 1 illustrates a write area on a related art NAND flash memory comprising a plurality of blocks B1, B2, B3, B4 . . . . In FIG. 1, a single block comprises four pages P1, P2, P3 and P4.
When writing a file to a related art NAND flash memory, metadata for the file is first written to the NAND flash memory, followed by the data constituting the file. While writing the data, the metadata is updated periodically (for example, every five minutes). Updating the metadata involves writing new metadata reflecting the data recording conditions up to the point when the metadata is updated.
In FIG. 1, metadata M1 is initially written on page P1 of block B1; data D1, D2 and D3 are written on pages P2, P3 and P4 of block B1, respectively; metadata M2 is updated on page P1 of block B2; and data D4, D5 and D6 are written on pages P2, P3 and P4 of block B2.
This related art process has at least the following problems:
Firstly, increased usage of the write area of a NAND flash memory occurs due to frequent updating of metadata, so the life span of the related art NAND flash memory can be reduced.
Secondly, if metadata are updated, the previous metadata is useless, resulting in a fragmented block which has a page of the useless metadata. In FIG. 1, the fragmented block is block B1 having page 1 where the useless metadata are written. The fragmented block can obstruct efficient usage of a related art NAND flash memory.
To use the page of the fragmented block where the useless metadata are written, necessary data is moved to another write area, and then all fragmented block is deleted.
In FIG. 1, in order to use page P1 of block B1 where the useless metadata M1 is written, data D1, D2 and D3 written on pages P2, P3 and P4 of block B1 is moved to another block (for example, block B3), and then block B1 is deleted.
Because deletion in a NAND flash memory is performed by the block as described above, frequent data deletion and movement can reduce the life span of a NAND flash memory.